# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=release-cli
pkgver=0.16.0
pkgrel=1
pkgdesc="Gitlab Release CLI"
arch=(loong64 x86_64)
url="https://gitlab.com/gitlab-org/release-cli"
license=(MIT)
depends=(glibc)
makedepends=(go)
source=($pkgname-$pkgver.tar.gz::https://gitlab.com/gitlab-org/$pkgname/-/archive/v$pkgver/$pkgname-v$pkgver.tar.gz)
sha512sums=('b66f23f783a612ed96839241d612baa5277065e2e512c09d62c6b772f1d670dab366aa71b1645a288580ef37ecb8e080f95ac735116c393b1255cfb0b3696e11')
b2sums=('451cf5e6aca31388e57daf6a8d78b8cf66fd377e144b432f6fe108faf7d42f0d2e676bbdb3e5971eb1c17a89d2cba889f8bbc7df1d83263b9e5814065c020673')

prepare() {
  mkdir -vp $pkgname-v$pkgver/build
}

build() {
  cd $pkgname-v$pkgver
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOPATH="${srcdir}"
  export GOFLAGS="-buildmode=pie  -mod=readonly -modcacherw"

  go build -ldflags "-compressdwarf=false -linkmode=external" -o build/$pkgname ./cmd/$pkgname
}

package() {
  install -vDm 755 $pkgname-v$pkgver/build/$pkgname -t "$pkgdir/usr/bin/"
  install -vDm 644 $pkgname-v$pkgver/LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 $pkgname-v$pkgver/{CHANGELOG,README}.md -t "$pkgdir/usr/share/doc/$pkgname/"
  cd $pkgname-v$pkgver/docs
  find . -type f -iname "*.md" -exec install -vDm 644 {} "$pkgdir/usr/share/doc/$pkgname/"{} \;
}
